<template>
    <div class="container">
        <mt-header title="地址列表">
            <router-link to="" slot="left">
                <mt-button icon="back" @click.native="$router.back(-1)">返回</mt-button>
            </router-link>
            <mt-button slot="right" @click="editAddress(0)">添加地址</mt-button>
        </mt-header>
        <div class="eventlist" v-if="addressList.length>0">
            <div class="row" v-for="(addr,i) in addressList" v-bind:key="i" @click="chooseAddr(addr.id)">
                <div class="row-span">
                    <div class="event-title">
                        <mt-badge size="small" color="#f8c961" v-if="addr.moren==1">默认</mt-badge>
                        <span class="event-title-name">{{addr.name}}</span>
                        <span>{{addr.tel}}</span>
                    </div>
                    <span class="event-date">{{addr.diqu}} {{addr.dizhi}} </span>
                </div>
                <div class=" point event-point" @click="editAddress(addr.id)">
                    <div class="iconfont icon-edit"></div>
                </div>
            </div>
        </div>
        <Nothing v-else></Nothing>
    </div>
</template>

<script>

    import Nothing from "../../components/Nothing"
    export default {
        name: "AddressList",
        components: { Nothing },
        data() {
            return {
                addressList: [],
                uid: this.$store.getters.getUserInfo.uid
            }
        },
        mounted() {
            this.getMyAddresses()
        },
        methods: {
            getMyAddresses() {
                this.$axios( {
                    method: 'post',
                    url: 'Index/listdizhi',
                    data: {
                        uid: this.uid
                    }
                } ).then( result => {
                    this.addressList = result.data
                } ).catch( error => {

                } );
            },
            editAddress( id ) {
                if (id)
                    this.$router.push( { path: '/addAddress/' + id } )
                else this.$router.push( '/addAddress/' )
            },
            chooseAddr(id){
                if(this.$route.name==='ChooseAddr'){
                    this.$emit('chooseAddr',id)
                    this.$router.back(  )
                }
            }
        },
    }
</script>

<style scoped>
    .container {
        padding: 0;
        background-image: url("../../../static/images/background.jpg");
        background-size: 100% 100%;
    }

    .eventlist {
        margin: 2vh;
        margin-top: 0;
        display: flex;
        flex-direction: column;
        background-color: #fff;
        padding: 2vh 20px;
        min-height: 92vh;
    }

    .eventlist .row {
        display: flex;
        flex-direction: row;
        padding: 16px 24px;
        border-top: 1px solid rgba(229, 229, 229, 1);
        justify-content: space-between;
    }

    .eventlist .row:first-child {
        border-top: none;
    }

    .eventlist .row .row-span {
        display: flex;
        flex-direction: column;
        width: 500px;
    }

    .eventlist .event-title-name {
        font-size: 26px;
        font-weight: 800;
    }

    .eventlist .event-date {
        margin-top: 8px;
        color: rgba(119, 119, 119, 1);
        font-size: 22px;
    }

    .event-point .point-icon {
        width: 30px;
        height: 30px;
        margin-top: 23px;
        margin-right: 20px;
    }

    .eventlist .event-point {
        height: 76px;
        line-height: 76px;
        color: #ff7f59;
        font-weight: 800;
        font-size: 32px;
        flex-shrink: 0;
    }
</style>
